package com.zjsru.studyplan1;

import java.util.Arrays;

/**
 * 有序数组的平方
 * 输入：nums = [-4,-1,0,3,10]
 * 输出：[0,1,9,16,100]
 * 解释：平方后，数组变为 [16,1,0,9,100]
 * 排序后，数组变为 [0,1,9,16,100]
 *
 *
 * */
public class sortedSquares {
    public int[] sortedSquares(int[] nums) {
        int n = nums.length;
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = nums[i]*nums[i];
        }
        Arrays.sort(num);
        return num;
    }
    public static void main(String[] args){
        int[] nums = new int[]{-4,-1,0,3,10};
        sortedSquares sortedSquares = new sortedSquares();
        System.out.println(sortedSquares.sortedSquares(nums));
    }
}
